define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'companybalancelog/index',
                    table: 'company_balance_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'admin.company.title', title: __('商家'),operate:false},
                        {field: 'create_time', title: __('时间'), operate:'RANGE', addclass:'datetimerange'},
                        {field: 'title', title: __('Title'),operate:'LIKE'},
                        {field: 'from', title: __('账变前'), operate:false},
                        {field: 'to', title: __('账变后'), operate:false},
                        {field: 'value', title: __('变化量'), operate:false},
                        {field: 'type_text', title: __('类型'), operate:false},
                        {field: 'type', title: __('类型'), visible:false,searchList: {"1":__('收入'),"2":__('支出')}, formatter: Table.api.formatter.normal},
                        {field: 'admin.username', title: __('用户名'),operate:'='},
                    ]
                ]
            });

            

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});